<template>
  <div class="app-container">
    <div class="formDiv">
      <el-form label-width="140px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="医院名称">
              <el-input v-model="params.name" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="审核状态">
              <el-select id v-model="params.examineStatus" name clearable>
                <el-option value="1" label="审核通过" />
                <el-option value="0" label="待审核" />
                <el-option value="2" label="审核驳回" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="维护状态">
              <!-- 0未维护 1已维护-->
              <el-select id v-model="params.isExist" name clearable>
                <el-option value="1" label="已维护" />
                <el-option value="0" label="未维护" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="创建时间">
              <el-date-picker
                v-model="time"
                type="daterange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="结算模式">
              <el-select name id clearable v-model="params.settlementType">
                <el-option :value="null" label="全部"></el-option>
                <el-option :value="1" label="预存款模式"></el-option>
                <el-option :value="0" label="回款模式"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button style="margin-left:60px" type="primary" @click="searchfun">查询</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="table" v-loading="tablaLoading">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" label="序号" align="center" :index="table_index" width="50" />
        <el-table-column prop="name" align="center" label="医院名称" width="180" />
        <el-table-column prop="reimbursementRatio" align="center" label="回款比率" width="180">
          <template slot-scope="scope">
            <span
              v-if="scope.row.reimbursementRatio && scope.row.reimbursementRatio!=0"
            >{{ scope.row.reimbursementRatio }}%</span>
          </template>
        </el-table-column>
        <el-table-column prop="settlementType" align="center" label="结算模式"></el-table-column>
        <el-table-column prop="creditLimit" align="center" label="信用额度" />
        <el-table-column prop="time" align="center" label="回款比率生效时间" />
        <el-table-column prop="settlementFee" align="center" label="入驻费" />
        <el-table-column prop="remarks" align="center" label="备注">
          <template slot-scope="scope">
            <div>
              <div class="text-overflow">{{ scope.row.remarks }}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop align="center" label="审核状态">
          <template slot-scope="scope">
            <span v-if="scope.row.examineStatus==0">待审核</span>
            <span v-if="scope.row.examineStatus==1">审核通过</span>
            <span v-if="scope.row.examineStatus==2">审核驳回</span>
          </template>
        </el-table-column>
        <el-table-column prop="updatedAt" align="center" label="审核通过时间">
          <template slot-scope="scope">
            <span v-if="scope.row.examineStatus==1">{{ scope.row.updatedAt }}</span>
          </template>
        </el-table-column>
        <el-table-column prop align="center" label="医院基础信息">
          <template slot-scope="scope">
            <span v-if="scope.row.isExist==0">未维护</span>
            <span v-if="scope.row.isExist==1">已维护</span>
          </template>
        </el-table-column>
        <el-table-column prop="createdBy" align="center" label="创建人">
          <template slot-scope="scope">
            <span>{{ scope.row.createdBy | userinfo }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createdAt" align="center" label="创建时间" />
        <el-table-column prop align="center" label="标识">
          <template slot-scope="scope">
            <span v-if="scope.row.dataFlag==0">新数据</span>
            <span v-if="scope.row.dataFlag==1">老数据</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.examineStatus==0">
              <el-button
                v-if="permissionJson.indexOf('AdminHospitalInformationProvider.hospitalExamine') !=-1"
                type="text"
                @click="edit(scope.row)"
              >审核</el-button>
            </div>
            <el-button
              v-if="permissionJson.indexOf('AdminHospitalInformationProvider.hospitalExamineDetail') !=-1"
              type="text"
              @click="edit(scope.row,'detail')"
            >详情</el-button>

            <el-button
              v-if="scope.row.examineStatus==2"
              @click="editfun(scope.row,'edit')"
              type="text"
            >编辑</el-button>
            <el-button v-if="scope.row.examineStatus==2" @click="detefun(scope.row)" type="text">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block" style="margin: 40px 0;">
      <el-pagination
        :current-page="params.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>
<script>
import hospitalEnter from "@/api/hospitalEnry";
import filter from "@/assets/filter.js";
export default {
  name: "Hospitalaudit",
  data() {
    return {
      tablaLoading: false,
      value: "",
      time: "",
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      total: 0,
      params: {
        name: "", // 医院名称
        examineStatus: null, // 审核状态 0为待审核 1为审核通过 2为审核驳回
        isExist: "", // 维护状态 0未维护 1已维护
        createdAtStartime: "", // 创建时间yyyy-MM-dd
        createdAtEndtime: "", // 创建时间yyyy-MM-dd
        pageNum: 1,
        pageSize: 10
      },

      tableData: []
    };
  },
  created() {
    this.$nextTick(() => {
      this.list();
    });
  },
  methods: {
    detefun(datas) {
      this.$confirm("此操作将删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async data => {
          console.log(data);
          const res = await hospitalEnter.detel({ id: datas.examineId });
          console.log(res);
          this.$message({
            type: "info",
            message: res.data.msg
          });
          if (res.data.code == 0) {
            this.list();
          }
        })
        .catch(() => {});
    },
    table_index(index) {
      return (this.params.pageNum - 1) * this.params.pageSize + index + 1;
    },
    searchfun() {
      this.params.pageNum = 1;
      if (this.params.examineStatus == "") {
        this.params.examineStatus = null;
      }

      this.params.createdAtStartime = this.time ? this.time[0] : "";
      this.params.createdAtEndtime = this.time ? this.time[1] : "";
      this.list();
    },
    list() {
      this.tablaLoading = true;
      hospitalEnter.examineList(this.params).then(res => {
        // console.log(res);
        if (res.data.code == 0) {
          this.tableData = res.data.data.list;
          this.total = res.data.data.count;
          const that = this;
          this.tablaLoading = false;
        } else {
          this.$message.warning(res.data.msg);
        }
      });
    },
    handleSizeChange(val) {
      this.params.pageNum = 1;
      this.params.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.list();
    },
    editfun(datas, name) {
      console.log(datas.examineId);
      this.$router.push({
        name: "enteryAdd",
        query: { type: "1", id: datas.examineId, name: name }
      });
    },
    edit(datas, name) {
      console.log(datas.examineId);
      this.$router.push({
        name: "enteryAdd",
        query: { type: "3", id: datas.examineId, name: name }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.text-overflow {
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.search {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .from {
    display: flex;
    justify-content: space-around;
    flex: 1;
    flex-flow: wrap;
    p {
      display: flex;
      align-items: center;
      select {
        width: 160px;
        border: 1px solid #dddd;
      }
      span {
        flex: none;
        margin-right: 10px;
      }
    }
  }
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
